package com.example.demo.service.impl;

import com.example.demo.dao.LevelDao;
import com.example.demo.entity.LevelBean;
import com.example.demo.entity.UserBean;
import com.example.demo.service.LevelService;
import com.example.demo.util.PageEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: demo
 * @ClassName LevelServiceImpl
 * @description:
 * @author: xtf
 * @create: YEAR−{MONTH}-DAY{HOUR}:12
 * @Version 1.0
 **/


@Service
public class LevelServiceImpl implements LevelService {

    @Autowired
    private LevelDao levelDao;


    @Override
    public Integer add(LevelBean levelBean) {
        return levelDao.insert(levelBean);
    }


    @Override
    public Integer update(LevelBean levelBean) {
        return levelDao.edit(levelBean);
    }

    @Override
    public Integer delete(Integer id) {
        return levelDao.del(id);
    }

    @Override
    public LevelBean one(Integer id) {
        return levelDao.getOneById(id);
    }

    @Override
    public PageEntity list(Integer pageNo, Integer pageSize, String name, String sortOrder) {

        // 根据页码 求 跳过多少条数据
        Integer jump = (pageNo-1)*pageSize;

        Integer count = levelDao.getCount(name);
        List<LevelBean> rows = levelDao.getPage(jump, pageSize, name, sortOrder);


        PageEntity<List> listPageEntity = new PageEntity<List>(rows,count);
        return listPageEntity;
    }
}